package com.bt.lms.ui.action.registration.stu;

import com.bt.lms.constants.BOConstant;
import com.bt.lms.ui.page.stu.PageMainStudentList;
import com.bt.lms.ui.vo.regstu.RegStuConditionQueryVo;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;

/**
 * 报名学员列表界面搜索按钮事件
 */
public class PageMainListSearchBtnAction implements EventHandler {

    /**
     * 报名学员列表界面
     */
    private PageMainStudentList pageMainStudentList;


    @Override
    public void handle(Event event) {


        //1.获取用户输入

        RegStuConditionQueryVo regStuConditionQueryVo = getInPrams();

        //2.验证用户输入
        String validateData = validateInPrams(regStuConditionQueryVo);


    }

    /**
     * 验证输入内容
     *
     * @param regStuConditionQueryVo 用户输入的信息
     * @return
     */
    private String validateInPrams(RegStuConditionQueryVo regStuConditionQueryVo) {


        return null;
    }

    /**
     * 获取用户输入
     *
     * @return
     */
    private RegStuConditionQueryVo getInPrams() {


        //封装对象
        RegStuConditionQueryVo regStuConditionQueryVo = new RegStuConditionQueryVo();

        //报名类型
        ComboBox unitCB = (ComboBox) pageMainStudentList.lookup("#unitCB");
        String unitCBValue = (String) unitCB.getValue();

        Integer unit = -1;
        switch (unitCBValue) {

            case "按招生计划":
                unit = 1;
                break;
            case "按招生院校":
                unit = 2;
                break;
            case "按招生层次":
                unit = 3;
                break;
            case "按招生专业":
                unit = 4;
                break;
        }
        regStuConditionQueryVo.setEnpType(unit);

        //模糊搜索
        TextField searchTF = (TextField) pageMainStudentList.lookup("#searchTF");
        String searchStr = searchTF.getText().trim();
        regStuConditionQueryVo.setVagueSearch(searchStr);


        //报名方式
        ComboBox applyWayCB = (ComboBox) pageMainStudentList.lookup("#applyWayCB");
        String applyWayCBValue = (String) applyWayCB.getValue();
        Integer applyWay = -1;
        switch (applyWayCBValue) {
            case "在线报名":
                applyWay = BOConstant.REG_STU_INFO_REQ_WAY_ONLINE;
                break;
            case "线下报名":
                applyWay = BOConstant.REG_STU_INFO_REQ_WAY_FACE;
                break;

        }
        regStuConditionQueryVo.setReqWay(applyWay);

        //邮箱状态
        ComboBox emailStatusCB = (ComboBox) pageMainStudentList.lookup("#emailStatusCB");
        String emailStatusCBValue = (String) emailStatusCB.getValue();
        Integer emailStatus = -1;
        switch (emailStatusCBValue) {
            case "已验证":
                emailStatus = BOConstant.REG_STU_INFO_EMAIL_STATUS_YES;
                break;

            case "未验证":
                emailStatus = BOConstant.REG_STU_INFO_EMAIL_STATUS_NO;
                break;


        }
        regStuConditionQueryVo.setEmailStatus(emailStatus);
        //录取状态
        ComboBox matriculateStatusCB = (ComboBox) pageMainStudentList.lookup("#matriculateStatusCB");
        String matriculateStatusCBValue = (String) matriculateStatusCB.getValue();
        Integer matriculateStatus = -1;
        switch (matriculateStatusCBValue) {
            case "待录取":
                matriculateStatus = 1;
                break;
            case "已录取":
                matriculateStatus = 2;
                break;
            case "未录取":
                matriculateStatus = 3;
                break;

        }
        regStuConditionQueryVo.setAdmissionStatus(matriculateStatus);

        //报名编号
        TextField stuNumNameTF = (TextField) pageMainStudentList.lookup("#stuNumNameTF");
        String stuNumNameStr = stuNumNameTF.getText().trim();
        regStuConditionQueryVo.setStuName(Integer.valueOf(stuNumNameStr));


        return regStuConditionQueryVo;
    }

    public PageMainStudentList getPageMainStudentList() {
        return pageMainStudentList;
    }

    public void setPageMainStudentList(PageMainStudentList pageMainStudentList) {
        this.pageMainStudentList = pageMainStudentList;
    }
}
